import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QLabel
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap

class AdvancedFilterDemo(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()
        
    def init_ui(self):
        layout = QVBoxLayout()
        
        self.info_label = QLabel('高级过滤器演示')
        
        btn = QPushButton('使用高级过滤器')
        btn.clicked.connect(self.advanced_filter_demo)
        
        layout.addWidget(btn)
        layout.addWidget(self.info_label)
        self.setLayout(layout)
        
    def advanced_filter_demo(self):
        # 复杂的过滤器组合
        complex_filter = """
        图片文件 (*.png *.jpg *.jpeg *.bmp *.gif *.tiff);;
        文档文件 (*.txt *.doc *.docx *.pdf *.rtf);;
        表格文件 (*.xls *.xlsx *.csv);;
        代码文件 (*.py *.cpp *.c *.h *.java *.js *.html *.css *.xml);;
        压缩文件 (*.zip *.rar *.7z *.tar *.gz);;
        所有文件 (*)
        """
        
        file_name, selected_filter = QFileDialog.getOpenFileName(
            self,
            "选择文件 - 高级过滤器",
            "",
            complex_filter,
            "图片文件 (*.png *.jpg *.jpeg *.bmp *.gif *.tiff)"  # 默认选择的过滤器
        )
        
        if file_name:
            self.info_label.setText(f"文件: {file_name}\n选择的过滤器: {selected_filter}")

            
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = AdvancedFilterDemo()
    window.show()
    sys.exit(app.exec_())